package pers.course.others;

import java.util.Scanner;

public class TowerOfHanoi {
    static int m = 0;

    public static void move(int disks, char N, char M) {
        System.out.println("第" + (++m) + "次移动：把" + disks + "号圆盘从" + N + "移动到" + M + "。");
    }

    public static void hanoi(int n, char A, char B, char C) {
        if (n == 1) {
            TowerOfHanoi.move(1, A, C);
        } else {
            hanoi(n - 1, A, C, B);
            TowerOfHanoi.move(n, A, C);
            hanoi(n - 1, B, A, C);
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        char A = 'A';
        char B = 'B';
        char C = 'C';
        System.out.println("请输入圆盘个数：");
        int disks = input.nextInt();
        TowerOfHanoi.hanoi(disks, A, B, C);
        System.out.println(">>移动了" + m + "次圆盘。");
        input.close();
    }
}
